package com.huang.PC;

import lombok.SneakyThrows;

import java.util.List;
import java.util.concurrent.TimeUnit;

public class P implements Runnable{
    private String name;
    List<Object> contain;

    public P(String name, List<Object> contain) {
        this.name = name;
        this.contain = contain;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            synchronized (contain){
                while (contain.size()==10){  //大于一生产一个消费一个    ==最大  生产消费随机
                    try {

                        contain.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                contain.add(new Object());
                System.out.println(name+"生产了。。");
                contain.notifyAll();

            }

            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        }





}
